package com.sasu.university_data.util;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result <T> {
    @ApiModelProperty(value = "返回码", example = "0")
    private String code;
    @ApiModelProperty(value = "提示信息")
    private String msg;
    @ApiModelProperty(value = "数据")
    private T data;
    @ApiModelProperty(value = "分页总数")
    private Integer count;

    /**
     * 一般应用在更新 新增 删除
     * @return
     */
    public Result<Object> success(){
        return new Result<>("200","操作成功",null,null);
    }

    /**
     * 前端返回数据
     * @param data
     * @return
     */
    public Result<Object> success(T data){
        return new Result<>("200","操作成功",data,null);
    }

    /**
     * 自定义状态码
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public Result<Object> success(String code,String msg,T data){
        return new Result<>(code,msg,data,null);
    }

    /**
     * 说明该方法错误不能展示出来
     * @return
     */
    public Result<Object> error(){
        return new Result<>("500","操作失败",null,null);
    }
}
